//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;
using OpenLS.Vml.Serialization;

namespace OpenLS.Vml.Drawing
{
    public class ShapeLayout : IOfficeXmlSerializable
    {
        internal const string xmlName = "shapelayout";

        private Ext _ext;

        private IdMap _idMap;
        private RegroupTable _RegroupTable  ;
        private Rules rules;

        public Ext Ext
        {
            get { return _ext; }
            set { _ext = value; }
        }

        public IdMap IdMap
        {
            get { return _idMap; }
            set { _idMap = value; }
        }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read(VmlConstants.OfficeNamespace + xmlName))
            {
                Ext = c.GetEnum<Ext>(VmlConstants.VmlNamespace+ "ext");
                while (c.ReaderLocalName != null)
                {
                    switch (c.ReaderLocalName)
                    {
                        case IdMap.xmlName:
                            IdMap = c.ReadOptionalElement<IdMap>(IdMap.xmlName);
                            break;
                        case "rules":
                            rules = c.ReadOptionalElement<Rules>("rules");
                            break;
                        case "regrouptable":
                            _RegroupTable = c.ReadOptionalElement<RegroupTable>("regrouptable");
                            break;
                        default: throw new NotImplementedException(c.ReaderLocalName);

                    }
                }
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (var c = context.Write(VmlConstants.OfficeNamespace + xmlName))
            {
                c.SetEnum(VmlConstants.VmlNamespace + "ext", Ext);
                c.WriteOptionalElement(IdMap);
                c.WriteOptionalElement(_RegroupTable);
                c.WriteOptionalElement(rules);
            }
        }

        #endregion
    }
}